window.addEventListener('load', function () {
    this.alert("请先登录您的账户再进行访问！！！");
    var is = this.document.querySelectorAll('i');
    var user = {
        name : '2910562670',
        code : '1'
    }
    for (var i = 0; i < is.length; i++) {
        is[i].onmouseover = function () {
            this.style.color = 'skyblue';
        }
        is[i].onmouseout = function () {
            this.style.color = '';
            if(inputs[0].value == user.code){
                is[0].style.color = 'skyblue';
            }
        }
    }   

   
    var inputs = this.document.querySelectorAll('input');
    inputs[0].onfocus = function () {
         this.style.borderBottom = '2px solid skyblue';
        is[1].style.color = 'skyblue';
    }
    var num1 = 0, num2 = 0;
    inputs[0].onblur = function () {
        this.style.borderBottom = '2px solid black';
        is[1].style.color = '';
        var isnum = /^\d+$/.test(this.value);
        if (this.value.length == 0) {
            alert('请输入账号！');
            num1 = 0;
        } else {
            if (this.value.length > 10 || this.value.length < 10 || !isnum) {
                alert('账号为10位数字');
                num1 = 0;
            } else {
                if (this.value == user.name) {
                    is[0].style.color = 'skyblue';
                    num1 = 1;
                } else {
                    alert('账户不存在')
                    is[0].style.color = '';
                    num1 = 2;
                }
            }
        }
    } 
    inputs[1].onfocus = function () {
        this.style.borderBottom = '2px solid skyblue';
        is[2].style.color = 'skyblue';
    }
    inputs[1].onblur = function () {
        this.style.borderBottom = '2px solid black';
        is[2].style.color = '';
        if (this.value == user.code) {
            num2 = 1;
        }else{    
             num2 = 0;
        }
    }
    var a = this.document.querySelector('a');
    a.onclick = function(){
        if(inputs[0].value.length != 0 && inputs[1].value.length != 0 && num1 ==1 && num2 ==1){
            a.href = 'command.html';
        } else if(inputs[0].value.length == 0 && inputs[1].value.length != 0 && num1 ==1 && num2 ==1){
            alert('请输入账号！');
        } else if(inputs[0].value.length != 0 && inputs[1].value.length == 0 && num1 ==1 && num2 ==0){
            alert('请输入密码');
        } else if(inputs[0].value.length != 0 && inputs[1].value.length != 0 && num1 ==0 && num2 ==1){
            alert('账号错误！');
        } else if(inputs[0].value.length != 0 && inputs[1].value.length != 0 && num1 ==1 && num2 ==0){
            alert('密码错误！');
        } else if(inputs[0].value.length != 0 && inputs[1].value.length != 0 && num1 ==2 && num2 ==1){
            alert('账号不存在！');

        } else if(inputs[0].value.length == 0 && inputs[1].value.length == 0 && num1 ==0 && num2 ==0){
            alert('请先输入账号和密码!');
        } else if(inputs[0].value.length != 0 && inputs[1].value.length != 0 && num1 ==2 && num2 ==0){
            alert('账号不存在');
        } else if(inputs[0].value.length != 0 && inputs[1].value.length != 0 && num1 ==0 && num2 ==0){
            alert('账号不存在！');
        }
        
    }
})  